const express = require('express');
const static = require('express-static');
const cookieParser = require('cookie-parser');
const cookieSession = require('cookie-session');
const bodyParser = require('body-parser');
const multer = require('multer');//上传文件模块
const fs = require('fs');
const pathLib = require('path');
const consolidate = require('consolidate');


var objMulter = multer({dest:'./www/uploade'});//dest 上传目标地址
var server = express();

server.listen(8080);
//1 解析cookie
server.use( cookieParser('GHJKLD') );
//2 使用session
//秘钥
var arr = [];
for( var i=0; i < 100000; i++ )
{
    arr.push( 'keys_'+Math.random() );
}

server.use( cookieSession({
    name:'zhanyisc_sess_id',
    keys:arr,
    maxAge:20*3600*1000
}) );
//3 post数据
server.use(bodyParser.urlencoded({extended:false}));
//接收文件上传数据
server.use( objMulter.any() );

//用于请求
/* server.use('/',function(req,res,next){
    console.log( req.query );
    console.log( req.body );
    console.log( req.cookies );
    console.log( req.session );
    console.log( req.files );
}); */



    /*配置模板引擎*/
    //1. 输出什么东西
    server.set( 'view engine','html' );
    //2. 模板文件放在哪儿
    server.set( 'views','./view' );
    //3. 哪种模板文件
    server.engine( 'html',consolidate.ejs );

    //接受用户请求
    server.get('/',function(req,res){
        console.log('xx');
       res.render( '1.ejs',{name:'zhangsan'} );
    });




//4 static数据
server.use(static('./www'));